﻿using System;
using System.Linq;
using System.Data.Linq;

namespace ConsoleListAndEnumerable
{
    class Program
    {
        static void Main(string[] args)
        {
            DataContext ctx = new DataContext("Data Source=.\\SQLEXPRESS;Initial Catalog=Student;User=sa;Password=123");
            Table<MyStudent> students = ctx.GetTable<MyStudent>();

            //var students = new List<MyStudent>
            //{
            //    new MyStudent{Id=1,Name="Mike",Age=20},
            //    new MyStudent{Id=2,Name="Rose",Age=19},
            //    new MyStudent{Id=3,Name="Steve",Age=21},
            //    new MyStudent{Id=4,Name="Jessica",Age=22},
            //    new MyStudent{Id=5,Name="Lisa",Age=23},
            //};
            //var temp1 = (from p in students where p.Age > 20 select p).ToList();
            var temp1 = from p in students where OlderThan(p.Age) select p;
            var temp2 = from p in temp1 where p.Name.IndexOf('e') > 0 select p;
            foreach (var item in temp2)
            {
                Console.WriteLine($"Name:{item.Name}\t Age:{item.Age}");
            }

            Console.ReadLine();
        }

        static bool OlderThan(int age)
        {
            return age > 20;
        }
    }
}
